package com.ylfstu.Homework;

import java.util.ArrayList;
@SuppressWarnings({"all"})
public class Homework01 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new News("新冠确诊病例超千万，数百万印度教信徒赴恒河\"圣浴\"引担忧"));
        arrayList.add(new News("男子突然想起两个月前钓的鱼还在网兜里，捞起一看赶紧放生"));
        for (int i = arrayList.size() - 1; i >= 0; i--) {
            News news = (News) (arrayList.get(i));
            System.out.println(processTitle(news.getTitle()));
        }

    }
    //写一个方法，显示新闻标题
    public static String processTitle(String title) {
        if (title == null)
            return "";
        if (title.length() > 15)
            return title.substring(0, 15) + "...";
        else
            return title;
    }
}

class News{
    private String title;
    private String content;

    @Override
    public String toString() {
        return "News{" +
                "title='" + title + '\'' +
                '}';
    }

    public News(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}